
{extend name='public/base' /}
{block name="css"}
<link href="__PLUG__/ztree/css/jquery.layout-latest.css" rel="stylesheet"/>
<link href="__PLUG__/ztree/css/zTreeStyle.css" rel="stylesheet"/>
<script src="__PLUG__/ztree/js/jquery.layout-latest.js"></script>
<script src="__PLUG__/ztree/js/jquery.ztree.all-3.5.js"></script>
{/block}
{block name="content"}

<div class="row">
    <div class="col-sm-3">
        <div class="ibox">
            <div class="ibox-title">
                <h5>角色权限组</h5>
                <div class="ibox-tools">
                    <a class="collapse-link">
                        <i class="fa fa-chevron-up"></i>
                    </a>
                    <a class="dropdown-toggle" data-toggle="dropdown" href="javascript:">
                        <i class="fa fa-wrench"></i>
                    </a>
                    <ul class="dropdown-menu dropdown-user">
                        <li>
                            <a  class="btn btn-box-tool" id="btnExpand">展开</a>
                        </li>
                        <li>
                            <a  class="btn btn-box-tool" id="btnCollapse">折叠</a>
                        </li>
                        <li>
                            <a class="btn btn-box-tool" id="btnRefresh">刷新部门</a>
                        </li>
                    </ul>

                </div>
            </div>
            <div class="ibox-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>

    <div class="col-sm-9">
        <div class="ibox xiaoshi">
            <div class="ibox-content">
                <div class="row">
                    <div class="col-sm-12 search-collapse">
                        <form class="form-inline" id="user-form">
                            <div class="select-list">
                                <ul>
                                    {:li_input('用户名称','username')}

                                    {:li_hidden('group_id','0')}

                                    {:li_select(['1'=>'禁止','2'=>'正常'],'用户状态','status')}

                                    {:li_time()}

                                    {:li_search()}

                                </ul>
                            </div>
                        </form>
                    </div>

                </div>
            </div>
        </div>

        <div class="ibox">
            <div class="ibox-content">
                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success  btn-rounded {:node('Admin/addAdmin')}" onclick="$.form.add()">
                        <i class="fa fa-plus"></i> 新增
                    </a>
                    <a class="btn btn-primary btn-rounded single " onclick="$.form.edit()">
                        <i class="fa fa-edit"></i> 修改
                    </a>
                    <a class="btn btn-danger btn-rounded multiple {:node('Admin/del')}" onclick="$.form.removeAll()">
                        <i class="fa fa-remove"></i> 删除
                    </a>
                    <a class="btn btn-warning btn-rounded" onclick="$.table.exportExcel()">
                        <i class="fa fa-download"></i> 导出
                    </a>
                </div>
                <div class="table-striped">
                    <table id="bootstrap-table" ></table>
                </div>
            </div>
        </div>
    </div>
</div>

{/block}

{block name="js"} <!--js处理区-->

<script>
    $(function() {
        table_data();
        tree_table();
    });
    function tree_table() {
        var url ="{:url('AuthGroup/auth_tree')}";
        var options = {
            url: url,
            expandLevel: 2,
            onClick : zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            $("#group_id").val(treeNode.id);
           // $("#parentId").val(treeNode.pid);
            $.table.search();
        }
    }

    $('#btnExpand').click(function() {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function() {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    $('#btnRefresh').click(function() {
        tree_table();
    });

    function table_data(){
        var options = {
            url: "{:url('index')}",
            deleteUrl:  "{:url('del')}?id={id}", //删除链接
            exportUrl:  "{:url('export')}",  //导出
            updateUrl: "{:url('editAdmin')}?id={id}", //编辑
            addUrl:    "{:url('addAdmin')}?id={id}", //添加
            detailUrl:  "/detailUrl",    //详细
            sortName: "id",
            sortOrder: "desc",
            modalName: "管理员",
            onEditableSave: onEditableSave, //行内编辑
            onDblClickRow:onDblClickRow, //双击行编辑
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'ID'
                },
                {
                    field : 'username',
                    title : '用户名',
                    align: 'center'
                },
                {
                    field : 'nickname',
                    title : '昵称',
                    align: 'center'
                },
                {
                    field : 'avatar',
                    title: '头像',
                    formatter: function(value, row, index) {
                        if($.common.isNotEmpty(row.avatar)){
                            return $.table.imageView(row.avatar);
                        }else {
                            return "-";
                        }
                    }
                },
                {
                    field: 'status',
                    title: '用户状态',
                    align: 'center',
                    editable : {
                        type : 'select',
                        title : '状态',
                        source : [{
                            value : 1,
                            text : '正常'
                        }, {
                            value : 0,
                            text : '禁用'
                        }]
                    }
                },
                {
                    field: 'sex',
                    title: '性别',
                    formatter: function(value, row, index) {
                        if(row.sex==0){
                            return '<span class="badge badge-primary">男</span>';
                        }else if(row.sex==1){
                            return '<span class="badge badge-info">女</span>';
                        }else {
                            return '<span class="badge badge-warning">位置</span>';
                        }
                    }
                },
                {
                    field : 'email',
                    title : '邮箱'
                },
                {
                    field : 'phone',
                    title : '手机号'
                },
                {
                    field : 'logins',
                    title : '登录次数',
                    align: 'center'
                },
                {
                    field: 'login_time',
                    title: '最后登录时间',
                    formatter: function(value, row, index) {
                        if (row.login_time!=0){
                            return $.common.timeToTime(row.login_time);
                        }else{
                            return "-";
                        }
                    }
                },
                {
                    field: 'create_time',
                    title: '添加时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return edit_del(row);
                    }

                }]
        };
        $.table.init(options);
    }


    function edit_del(row) {
        if(row.id==1){
            return '不允许编辑';
        }else {
            var actions = [];
            actions.push('<a class="btn btn-xs btn-success  {:node(\'Admin/addAdmin\')}" data-original-title="编辑" data-toggle="tooltip" onclick="$.form.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i></a>');
            actions.push('<a class="btn btn-danger btn-xs {:node(\'Admin/del\')}" data-original-title="删除" data-toggle="tooltip" onclick="$.form.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i></a>');
            return actions;
        }
    }

    function quan(id) {
        var url="{:url('userGroup')}?id="+id;
        $.form.OpenForm('授权',url,'','',true);
    }

    //双击行编辑
    function onDblClickRow(row) {
        // alert(JSON.stringify(row))
        if (row.id==1){
            $.models.toastr_warning("超级管理员不允许编辑");
        }else {
            $.form.edit(row.id);
        }
    }
    function onEditableSave (field, row, oldValue) {
        $.form.Change_status("{:url('common/changeStatus')}","auth_group",row.id,field,row[field]);
    }
</script>

{/block}
